package ca.mcgill.model.digraph.utils;

import java.util.Map;

import ca.mcgill.model.digraph.Digraph;
import ca.mcgill.model.digraph.DigraphEdge;
import ca.mcgill.model.implementation.ImplementationModel;
import ca.mcgill.model.implementation.Task;
import ca.mcgill.model.implementation.Transaction;

/**
 * This class aggregates methods to printout the information about the digraph.
 * 
 * @author EW228618
 * 
 */
public class DigraphDisplay {

	public void printoutDigraphForTask(Digraph digraph) {

		for (DigraphEdge edge : digraph.getEdges()) {

			System.out.println(edge.getSrcVertex().getName() + "--"
					+ edge.getInterArrivalTime() + "-->"
					+ edge.getDstVertex().getName());

		}

	}

	public void printoutDigraphWithWCET(Digraph digraph) {

		for (DigraphEdge edge : digraph.getEdges()) {

			System.out.println(edge.getSrcVertex().getName() + " ("
					+ edge.getSrcVertex().getAction().getBCET() + " - "
					+ edge.getSrcVertex().getAction().getWCET() + ") " + "--"
					+ edge.getInterArrivalTime() + "-->"
					+ edge.getDstVertex().getName());

		}

	}

	public void printoutDigraphForAllTasks(Map<Task, Digraph> taskToDigraph,
			ImplementationModel implModel) {

		for (Transaction transaction : implModel.getTransactions()) {

			System.out.println("$$$$$---Transaction---$$$$$$\n\n");

			for (Task task : transaction.getTasksInTransaction()) {

				System.out.println("Task: " + task.getName());

				printoutDigraphForTask(taskToDigraph.get(task));

				System.out.println("\n\n");

			}

		}

	}

	public void printoutDigraphForAllTasksWithWCET(
			Map<Task, Digraph> taskToDigraph, ImplementationModel implModel) {

		for (Transaction transaction : implModel.getTransactions()) {

			System.out.println("$$$$$---Transaction---$$$$$$\n\n");

			for (Task task : transaction.getTasksInTransaction()) {

				System.out.println("Task: " + task.getName());

				printoutDigraphWithWCET(taskToDigraph.get(task));

				System.out.println("\n\n");

			}

		}

	}

	public void printoutDigraphForAllTasksWithWCETandDL(
			Map<Task, Digraph> taskToDigraph, ImplementationModel implModel) {

		for (Transaction transaction : implModel.getTransactions()) {

			System.out.println("$$$$$---Transaction---$$$$$$\n\n");

			for (Task task : transaction.getTasksInTransaction()) {

				System.out.println("Task: " 
						+ task.getName() + " priority "	+ task.getPriority() 
						+ " DL: " 
						+ task.getFsm().getTransitions().get(0).getRelativeDeadline());

				printoutDigraphWithWCET(taskToDigraph.get(task));

				System.out.println("\n\n");

			}

		}

	}

}
